skit.define("library.misc.templatehelpers:js", ["skit.platform.iter:js","skit.platform.navigation:js","skit.platform.string:js","skit.platform.urls:js","skit.thirdparty.handlebars:runtime","third_party.moment:js","third_party.twemoji:js"], function() { return ((function(skit_platform_iter,skit_platform_navigation,skit_platform_string,skit_platform_urls,skit_thirdparty_handlebars,third_party_moment,third_party_twemoji) { var module = {exports: {}}; var defined = null; function define() { for (var i = 0; i < arguments.length; i++) { if (typeof arguments[i] == 'function') { defined = arguments[i](); break; } } } define.amd = true; var result = (function library_misc_templatehelpers_js() {/** * @license * Copyright 2016 Cluster Labs, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var iter = skit_platform_iter; var navigation = skit_platform_navigation; var string = skit_platform_string; var urls = skit_platform_urls; var Handlebars = skit_thirdparty_handlebars; var moment = third_party_moment; var twemoji = third_party_twemoji; var SHORT_ISO_DATE_FORMAT = 'MMM D, YYYY'; var SHORT_DATE_FORMAT = 'M/DD/YY h:mm a'; var SHORT_DATE_FORMAT_NOTIME = 'M/DD/YY'; var LONG_DATE_FORMAT = 'MMMM Do YYYY, h:mm a'; var LONG_DATE_FORMAT_NOTIME = 'MMMM D, YYYY'; function prettyPrintNumber(value, opt_decimalDigits) { // ensure value is numeric. if (!value) { return '0' + (opt_decimalDigits ? '.000000000000'.substring(0, opt_decimalDigits + 1) : ''); } var intValue = Math.floor(value); var decimal = value - intValue; if (opt_decimalDigits) { var tenner = Math.pow(10, opt_decimalDigits); decimal = (Math.round(value * tenner) / tenner) - Math.floor(value); } var formatted = ''; while (intValue > 0) { var remainder = (intValue % 1000); intValue = Math.floor(intValue / 1000); if (intValue > 0) { if (remainder < 10) { remainder = '00' + remainder; } else if (remainder < 100) { remainder = '0' + remainder; } } formatted = (remainder + (formatted ? ',' : '')) + formatted; } if (decimal) { // add ".47" var decimalStr = decimal + ''; if (opt_decimalDigits) { var end = (1 + opt_decimalDigits + 1); decimalStr = decimalStr.substring(1, end); } else { decimalStr = decimalStr.substring(1); } formatted += decimalStr; } return formatted; } // // COMMON TEMPLATE HELPERS // function dateFromNumber(date) { // TODO(Taylor): Remove crazy date string parsing crap sometime. if (date && date.match && date.match(/^\d{4}-\d{2}-\d{2}T.+Z$/)) { return new Date(Date.parse(date)); } // probably a non-ms unix timestamp if (date < 1577779200) { date *= 1000; } date = new Date(date); return date; } function breakLongWords(sanitized) { return sanitized.replace(/\w{20}/g, function(s) { return s + ''; }); } function zeroPad(n, width) { n = '' + n; while (n.length < width) { n = '0' + n; } return n; } var ALL_HELPERS = { json: function(arg, opt_pretty) { // + here forces numeric. default last argument is handlebars context obj, // so is truthy if not forced to evaluate as a number first. return JSON.stringify(arg, null, +opt_pretty ? 2 : null).replace(/[<>'&\u2028\u2029]/g, function(char) { var str = char.charCodeAt(0).toString(16); return '\\u0000'.substring(0, 2 + (4 - str.length)) + str; }); }, spaceless: function(options) { var content = options.fn(this); return content.replace(/>\s+<'); }, pluralize: function(number, single, plural) { return (number === 1) ? single : plural; }, timeFromNow: function(context, block) { if (!context) { return 'Never'; } var date = dateFromNumber(context); var now = +(new Date()); if (now - date < (2 * 60 * 1000)) { return 'Just now'; } return moment(date).fromNow(); }, shortISODate: function(isoString) { return moment(isoString).format(SHORT_ISO_DATE_FORMAT); }, shortDate: function(context) { var date = dateFromNumber(context); return moment(date).format(SHORT_DATE_FORMAT); }, shortDateNoTime: function(context) { var date = dateFromNumber(context); return moment(date).format(SHORT_DATE_FORMAT_NOTIME); }, longDate: function(context) { var date = dateFromNumber(context); return moment(date).format(LONG_DATE_FORMAT); }, longDateNoTime: function(context) { var date = dateFromNumber(context); return moment(date).format(LONG_DATE_FORMAT_NOTIME); }, formatNumber: prettyPrintNumber, formatCurrency: function(amount) { return '$' + prettyPrintNumber(amount, 2); }, centsToDollars: function(amount) { var isNegative = (amount < 0) ? '-' : ''; if (isNegative == '-') { amount *= -1; } return isNegative + '$' + prettyPrintNumber(amount / 100, 2); }, formatDuration: function(totalSeconds) { // Round up from zero so the smallest amount // we have is one second in the case of partial seconds. totalSeconds = Math.ceil(totalSeconds || 0); var HOUR = 60 * 60; var seconds = Math.floor(totalSeconds % 60); var hours = Math.floor(totalSeconds / HOUR); var minutes = Math.floor((totalSeconds - (hours * HOUR)) / 60); var parts = []; if (hours) { parts.push(hours + 'h'); } if (minutes && hours < 10) { parts.push(minutes + 'm'); } // not if (seconds) because seconds might be 0, we want "0s" to show up. if (hours < 1 && minutes < 10) { parts.push(seconds + 's'); } // non-breaking space ( ): return parts.join('\u00A0'); }, bodyText: function(context, block) { var graphs = (context || '').split(/[\n\r]{2}/); var result = []; iter.forEach(graphs, function(substr) { result.push('
');
var sanitized = breakLongWords(Handlebars.Utils.escapeExpression(substr).replace('\n', '
'));
result.push(sanitized);
result.push('